package component
{
	import flash.display.Sprite;
	import flash.geom.Point;
	
	import functional.ADclickAble;
	import functional.ADdragAble;
	import functional.ADmouseDownAble;
	import functional.ADmouseUpAble;

	public class ADbaseScroll extends ADbaseComponent
	{
		private var downab:ADmouseDownAble=new ADmouseDownAble;
		private var upab:ADmouseUpAble=new ADmouseUpAble;
		private var dragab:ADdragAble=new ADdragAble;
		public function ADbaseScroll()
		{
			super();
			initab()
		}
		protected function initab():void
		{
			registerAble(downab);
			downab.stateFunc=downHandle;
			dragab.stateFunc=draghandle;
			upab.stateFunc=upHandle;
		}
		protected function downHandle(skins:*,index:int):void
		{
			registerAble(dragab);
			dragab.rec||=(skins[0] as Sprite).getRect(this);
			registerAble(upab);
			dragab.isable=true;
			(skins[index]).startDrag();
			//				var p:Point=new Point(mouseX,mouseY);
			//				var newp:Point=this.
			skins[index].x=mouseX-skins[index].width/2;
			skins[index].y=mouseY-skins[index].height/2
		}
		protected function upHandle(skins:*,index:int):void
		{
			skins[index].stopDrag();
			dragab.isable=false;
			downab.isable=true;
		};
		protected function draghandle(skins:*,index:int):void
		{
			trace("ADbaseScroll.draghandle(skins, index)",dragab.rec.width,skins[index].x,skins[index].x/dragab.rec.width);
			posPoint=new Point(skins[index].x,skins[index].y);
			downab.isable=false;
		}
		private var posPoint:Point;
		public function get posPer():Point
		{
			return new Point(posPoint.x/dragab.rec.width,posPoint.y/dragab.rec.height);
		}
	}
}